<?php
require_once 'recuperation.php';
include 'connexion (2).php';
$idEN=null;

if(isset($_GET['idEN']))
{
    $idEN=$_GET['idEN'];
}

$idStage=null;

if(isset($_GET['idStage']))
{
    $idStage=$_GET['idStage'];
}


if(isset($_POST['jrdd'])&&isset($_POST['modd'])&&isset($_POST['andd']))
{
    $dd=$_POST['andd']."-".$_POST['modd']."-".$_POST['jrdd'];
}

if(isset($_POST['jrdf'])&&isset($_POST['modf'])&&isset($_POST['andf']))
{
    $df=$_POST['andf']."-".$_POST['modf']."-".$_POST['jrdf'];
}

if(isset($_POST['sujSA']))
{
    $sujet=$_POST['sujSA'];
}else{
       $sujet=$_POST['sujS'];
     }

$etat=null;
if(isset($_POST['etats']))
{
    $etat=$_POST['etats'];
}

$idform=null;
if(isset($_POST['formSA']))
{
    $idform=$_POST['formSA'];
}else{
       $idform=$_POST['form'];
     }

$action=null;
if(isset($_GET['action']))
{
    $action=$_GET['action'];
}


$referer=$_SERVER['HTTP_REFERER'];

   if($action!="modifier")
   {
        $adresse=recupAdresse( $idEN);
        $req1="insert into stage (IDSTAGE,DATEDEBUT,DATEFIN,ETATSTAGE,ADRESSESTAGE,SUJETSTAGE,IDENTREPRISE,IDFORMATION)
                           value (null,'$dd','$df','En attente','$adresse','$sujet',$idEN,$idform)";
        $req12=$connexion->exec($req1);
        
        if($req12)
        {
            echo '<script type="text/javascript">alert("Ajout réussi");</script>'; 
             header("Location: ".$referer);
            
            //header("Location:ajouterOffre.php?action=ajouter");
        }ELSE{
                echo '<script type="text/javascript">alert("Ajout échoué");</script>';
                header("Location: ".$referer);
            
            }
    
   }else {
       
        $req1="update stage set DATEDEBUT='".$dd."',DATEFIN='".$df."',ETATSTAGE='".$etat."',SUJETSTAGE='".$sujet."',IDFORMATION=".$idform." where IDSTAGE=".$idStage;
           
        $req12=$connexion->exec($req1);
          header("Location: ".$referer);
        if($req12)
        {
          
            echo '<script type="text/javascript">alert("Modification réussi");</script>';     
            header("Location: ".$referer);
        }
    }
    

?>
